<?php

class AvaliacoesControl extends Avaliacoes{

	public function insertAvaliacoes($arr){
		try {
			$obj = new Avaliacoes();
			foreach($arr as $chave => $valor){
				$chave = ucfirst($chave);
				$met = 'set'.$chave;
				$obj->$met($valor);
			}
			$db = new Db;
			$db->Insert('avaliacoes',$obj);
			$this->lista = $db->res;
		}catch (Exception $e) {
			echo 'Erro: ',  $e->getMessage();
		}
	}
	public function updateAvaliacoes($arr){
		try {
			$obj = new Avaliacoes();
			foreach($arr as $chave => $valor){
				$chave = ucfirst($chave);
				$met = 'set'.$chave;
				$obj->$met("'".$valor."'");
			}
			$db = new Db;
			$db->Update('avaliacoes',$obj);
			$this->lista = $db->res;
		}catch (Exception $e) {
			echo 'Erro: ',  $e->getMessage();
		}
	}
	public function deleteAvaliacoes($id){
		try {
			$db = new Db;
			$db->Delete('avaliacoes',$id);
			$this->lista = $db->res;
		} catch (Exception $e) {
			echo 'Erro: ',  $e->getMessage();
		}
	}
	public function consultarAvaliacoes($parametros){
		try {
			$campos = array('*');
			$where = 'idavaliacoes = '.$parametros;
			$order = '';
			$db = new Db;
			$db->Select('avaliacoes',$campos,$where,$order);
			$this->lista = json_encode(Control::arrayUtf8_converter($db->res[0]));
		}catch (Exception $e) {
			echo 'Erro: ',  $e->getMessage();
		}
	}
	public function listarAvaliacoes($array){
		try {
			$campos = array('avaliacoes.*, usuarios.login');
			$where = 'avaliacoes.pratos_idpratos = '.$array['parametros'];
			$order = 'avaliacoes.idavaliacoes DESC';
			$db = new Db;
			$db->Select('avaliacoes INNER JOIN usuarios ON usuarios.idusuarios = avaliacoes.usuarios_idusuarios',$campos,$where,$order);
			$this->lista = json_encode(Control::arrayUtf8_converter($db->res));
		}catch (Exception $e) {
			echo 'Erro: ',  $e->getMessage();
		}
	}	
}
?>